package com.luxury.adpter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.BitmapTransformation;
import com.google.gson.Gson;
import com.luxury.R;
import com.luxury.bean.GlobalChildBean;
import com.luxury.helper.RecyclerViewAdapterHelper;
import com.luxury.utils.BitmapCircleTransformation;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;


/**
 * Created by Gabriel on 2016/12/19.
 */

public class GlobalRecylerAdapter extends RecyclerViewAdapterHelper<GlobalChildBean.CommentShowDisplaysBean> {

    public GlobalRecylerAdapter(Context mContext, List<GlobalChildBean.CommentShowDisplaysBean> mList) {
        super(mContext, mList);
        this.mContext = mContext;
        this.mList = mList;
    }

    @Override
    public int getItemViewType(int position) {
        if (mList.get(position).getSort() == 0) {
            return 2;
        }
        return 1;
    }

    @Override
    public RecyclerView.ViewHolder onCreateMyViewHolder(ViewGroup parent, int viewType) {
        View view = null;
        switch (viewType) {
            case 1:
                view = mInflater.inflate(R.layout.item_type1_globalfragment, parent, false);
                return new ViewHolderType1(view);
            case 2:
                view = mInflater.inflate(R.layout.item_type2_globalfragment, parent, false);
                return new ViewHolderType2(view);
        }
        return null;
    }

    @Override
    public void onBindMyViewHolder(RecyclerView.ViewHolder holder, int position) {
        GlobalChildBean.CommentShowDisplaysBean bean = mList.get(position);
        if (holder instanceof ViewHolderType1) {
            Glide.with(mContext).load(bean.getImgurl()).into(((ViewHolderType1) holder).imageview_global_item1);
        } else if (holder instanceof ViewHolderType2) {
            Glide.with(mContext).load(bean.getHeadImg()).transform(new BitmapCircleTransformation(mContext)).into(((ViewHolderType2) holder).image_headImg_global_item2);
            ((ViewHolderType2) holder).textview_nickname_global_item2.setText(bean.getNickName());
            List<String> imgs = bean.getImgs();
            String imgbaseUrl = "http://pic.secooimg.com/";
            Glide.with(mContext).load(imgbaseUrl + imgs.get(0)).into(((ViewHolderType2) holder).imageview_global_item2);
            ((ViewHolderType2) holder).text_content_global_item2.setText(bean.getContent());
            Date date = new Date(bean.getCreateDate());
            //标准日历系统类
            GregorianCalendar gc = new GregorianCalendar();
            gc.setTime(date);
            //java.text.SimpleDateFormat，设置时间格式
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            //得到毫秒值转化的时间
            String time = format.format(gc.getTime());
            ((ViewHolderType2) holder).text_createDate_global_item2.setText(time);

            ((ViewHolderType2) holder).text_praiseCount_global_item2.setText(bean.getPraiseCount()+"");

        }
    }


    /*----------------------------------type0的holder------------------------------------------------------*/
    class ViewHolderType1 extends RecyclerView.ViewHolder {
        private ImageView imageview_global_item1;

        public ViewHolderType1(View itemView) {
            super(itemView);
            imageview_global_item1 = (ImageView) itemView.findViewById(R.id.imageview_global_item1);
        }
    }


    /*---------------------普通item=================================>>>>>>>>>>>>>>>>>>>>>>>>>*/
    class ViewHolderType2 extends RecyclerView.ViewHolder {
        private ImageView image_headImg_global_item2;
        private TextView textview_nickname_global_item2;
        private ImageView imageview_global_item2;
        private TextView text_content_global_item2;
        private TextView text_createDate_global_item2;
        private TextView text_praiseCount_global_item2;

        public ViewHolderType2(View itemView) {
            super(itemView);
            image_headImg_global_item2 = (ImageView) itemView.findViewById(R.id.image_headImg_global_item2);
            textview_nickname_global_item2 = (TextView) itemView.findViewById(R.id.textview_nickname_global_item2);
            imageview_global_item2 = (ImageView) itemView.findViewById(R.id.imageview_global_item2);
            text_content_global_item2 = (TextView) itemView.findViewById(R.id.text_content_global_item2);
            text_createDate_global_item2 = (TextView) itemView.findViewById(R.id.text_createDate_global_item2);
            text_praiseCount_global_item2 = (TextView) itemView.findViewById(R.id.text_praiseCount_global_item2);

        }
    }
}
